package com.dcoinpay.sys.controller;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Api;
import java.util.List;
import com.dcoinpay.common.aop.annotation.LogAnnotation;
import com.dcoinpay.common.utils.DataResult;

import com.dcoinpay.sys.entity.Node;
import com.dcoinpay.sys.service.NodeService;



/**
 * 节点链信息
 *
 * @author dcoinpay
 * @date 2020-07-01 23:05:40
 */
@Controller
@RequestMapping("/sys/node")
@Api(tags = "节点链信息管理")
public class NodeController {
    @Autowired
    private NodeService nodeService;


    /**
    * 跳转到页面
    */
    @GetMapping("/listview")
    public String listview() {
        return "sys/node/list";
    }

    @ApiOperation(value = "新增节点链信息")
    @PostMapping("/add")
    @LogAnnotation(title = "节点链信息", action = "新增节点链信息")
    @RequiresPermissions("sys:node:add")
    @ResponseBody
    public DataResult<Node> add(@RequestBody Node node){
        nodeService.save(node);
        return DataResult.success();
    }

    @ApiOperation(value = "删除节点链信息")
    @LogAnnotation(title = "节点链信息", action = "删除节点链信息")
    @DeleteMapping("/delete")
    @RequiresPermissions("sys:node:delete")
    @ResponseBody
    public DataResult<Node> delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        nodeService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新节点链信息")
    @LogAnnotation(title = "节点链信息", action = "更新节点链信息")
    @PutMapping("/update")
    @RequiresPermissions("sys:node:update")
    @ResponseBody
    public DataResult<Node> update(@RequestBody Node node){
        nodeService.updateById(node);
        return DataResult.success();
    }

    @ApiOperation(value = "查询节点链信息")
    @PostMapping("/list")
    @RequiresPermissions(value ={"sys:node:list","sys:coin:add"})
    @ResponseBody
    public DataResult<Object> findListByPage(@RequestBody Node node){
//    	node.setLimit(1000);
        Page<Node> page = new Page<Node>(node.getPage(), node.getLimit());
        QueryWrapper<Node> queryWrapper = new QueryWrapper<Node>();
      //查询条件示例
        if(StringUtils.isNotBlank(node.getName())) {
            queryWrapper.like("name", node.getName());
        }
        IPage<Node> iPage = nodeService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
